//
//  SHD_TalkTableViewCell.m
//  B段项目
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 谢美娜. All rights reserved.
//

#import "SHD_TalkTableViewCell.h"

@implementation SHD_TalkTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if ( self) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.textColor = [UIColor grayColor];
        _midImageView = [[UIImageView alloc]init];
        _titleLabel = [[myTitleLabel alloc]init];
        _contectLabel = [[myContectLabel alloc]init];
        _likeLabel = [[UILabel alloc]init];
        _likeLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_nameLabel];
        [self.contentView addSubview:_midImageView];
        [self.contentView addSubview:_titleLabel];
        [self.contentView addSubview:_contectLabel];
        [self.contentView addSubview:_likeLabel];

    }
    return self;
    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    _nameLabel.frame = CGRectMake(15 * FitWidth, 15 * FitHeight, 100 * FitWidth, 10 * FitHeight);
    [_nameLabel NightWithType:UIViewColorTypeNormal];
    _titleLabel.frame = CGRectMake(_nameLabel.frame.origin.x, _nameLabel.frame.origin.y + _nameLabel.frame.size.height + 10 * FitHeight, 345 *FitWidth, 45 * FitHeight);
    _midImageView.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y + 10 * FitHeight + _titleLabel.frame.size.height, 345 * FitWidth, 200 * FitHeight);
    _contectLabel.frame = CGRectMake(_midImageView.frame.origin.x, _midImageView.frame.size.height + _midImageView.frame.origin.y + 10 * FitHeight, 345 * FitWidth, 55 * FitHeight);
    _likeLabel.frame = CGRectMake(260 * FitWidth, _contectLabel.frame.origin.y + _contectLabel.frame.size.height + 10 * FitHeight, 100 * FitWidth, 10 * FitHeight);
    _likeLabel.textAlignment = 2;
    _titleLabel.numberOfLines = 0;
    _contectLabel.numberOfLines = 0;
    _likeLabel.font = [UIFont systemFontOfSize:10 * FitWidth];
    _midImageView.userInteractionEnabled = YES;
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(savePhoto:)];
    longPress.minimumPressDuration = 1;
    [_midImageView addGestureRecognizer:longPress];

    
}
#pragma mark 图片保存

-(void)savePhoto:(UILongPressGestureRecognizer *)gesture
{

    
    if (gesture.state == UIGestureRecognizerStateBegan) {
        UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                      initWithTitle:@"提示"
                                      delegate:self
                                      cancelButtonTitle:@"取消"
                                      destructiveButtonTitle:@"保存到相册"
                                      otherButtonTitles:nil];
        actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        [actionSheet showInView:self.contentView];
        
    }
}
#pragma mark 保存相片方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        UIImageWriteToSavedPhotosAlbum(_midImageView.image, self, NULL, NULL);
        
    }
}

-(void)setTalkModel:(SHD_TalkList *)talkModel
{
    _talkModel = talkModel;_nameLabel.text = [NSString stringWithFormat:@"%@ · %@", talkModel.Name, talkModel.enname];
    _nameLabel.font = [UIFont fontWithName:@"STHeitiSC-Light" size:10 * FitWidth];
    [_midImageView sd_setImageWithURL:[NSURL URLWithString:talkModel.coverimg] placeholderImage:[UIImage imageNamed:@"SHD_Scroll"]];
    _titleLabel.text = talkModel.title;
    _contectLabel.text = talkModel.content;
    _contectLabel.textType = [NSNumber numberWithInteger:LabelColorGray];
    _likeLabel.text = [NSString stringWithFormat:@"有%@人喜欢", talkModel.like];
    _likeLabel.font = [UIFont fontWithName:@"STHeitiSC-Light" size:10 * FitWidth];

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
